package cn.yto.wdgj.wdgjgptdigitaltool.controller;

import cn.yto.response.BaseResponse;
import cn.yto.response.DataResult;
import cn.yto.wdgj.wdgjgptdigitaltool.entity.dto.response.FileResp;
import cn.yto.wdgj.wdgjgptdigitaltool.service.CaseImportService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping(value = "/case")
@Api(value = "导入测试用例", tags = {"导入测试用例"})
public class CaseImportController {
    @Autowired
    private  CaseImportService caseImportService;
    @RequestMapping(value = "/import", method = RequestMethod.POST)
    @ApiOperation(value = "导入测试用例", httpMethod = "POST", notes = "导入测试用例")
    public DataResult<BaseResponse> importExcel(@RequestParam("file") MultipartFile file){
        DataResult<BaseResponse> resp=new DataResult<>();
        if (file.isEmpty()){
            resp.setMessage("请选择要上传的文件");
            return resp;
        }
        try {
            String result =caseImportService.importExcel(file);
            resp.setMessage(result);
            return resp;
        }catch (Exception e){
            resp.setMessage("导入失败");
            return resp;

        }

    }

}


